package com.an.spring.beanlife;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

public class MyBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object o, String s) throws BeansException {
        if("car".equals(s)){
            Car car = (Car) o;
            if(car.getColor() == null){
                System.out.println("调用BeanPostProcessor.postProcessBeforeInitialization(),设置车的颜色为黑色");
                car.setColor("黑色黑色------》》");
            }
        }
        return o;
    }

    @Override
    public Object postProcessAfterInitialization(Object o, String s) throws BeansException {
       if("car".equals(s)){
           Car car = (Car) o;
           if(car.getMaxSpeed() >= 200){
               System.out.println("调用BeanPostProcessor.postProcessAfterInitialization,速度大于199，调整为200");
               car.setMaxSpeed(200);
           }
       }

        return o;
    }
}
